package org.dromara.answerFront.service.impl;

import lombok.RequiredArgsConstructor;
import org.dromara.answer.domain.bo.AiOptionsBo;
import org.dromara.answer.domain.bo.AiQuestionsBo;
import org.dromara.answer.domain.vo.AiQuestionsVo;
import org.dromara.answer.service.IAiOptionsService;
import org.dromara.answer.service.IAiQuestionsService;
import org.dromara.answerFront.service.IFrontQuestionsService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class FrontQuestionsServiceImpl implements IFrontQuestionsService {

    private final IAiQuestionsService questionsService;
    private final IAiOptionsService optionsService;

    @Override
    public List<AiQuestionsVo> queryList(AiQuestionsBo bo) {
        List<AiQuestionsVo> queryList = questionsService.queryList(bo);

        queryList.forEach(item -> {
            item.setOptions(optionsService.queryListByQuestionId(item.getQuestionId()));
        });

        return queryList;
    }


    @Override
    public boolean insert(AiQuestionsBo questions) {
        questionsService.insertByBo(questions);
        for (AiOptionsBo option : questions.getOptions()) {
            option.setQuestionId(questions.getQuestionId());
            optionsService.insertByBo(option);
        }
        return false;
    }
}
